<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 4:31
 */
namespace app\backstage\controller;
use app\backstage\model\GoodscatModel;
use cmf\controller\AdminBaseController;

class GoodscatController extends AdminBaseController{
    /**
     * 类别列表页面
    */
    public function index(){
        $param = $this->request->param();
        //获取商品所有商品类别
        $g          = new GoodscatModel();
        $rest       = $g->index($param);
        $rest->appends($param);
        $this->assign('data',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('goodscat/index');
    }
    /**
     * 类别添加页面
    */
    public function add(){
        return $this->fetch('goodscat/add');
    }
    /**
     * 类别添加操作
    */
    public function addPost(){
        $date       = $this->request->param();
        $g          = new GoodscatModel();
        $rest       = $g->add($date);
        if($rest != false){
            $this->success('添加成功！', url("Goodscat/index"));
        }else{
            $this->error('添加失败');
        }

    }
    /**
     * 类别修改页面
    */
    public function detail(){
        //根据id获取该条类别信息
        $id          = $this->request->param('id');
        $g           = new GoodscatModel();
        $rest        = $g->getGcone($id);
        $this->assign('data',$rest);
        return $this->fetch('edit');
    }
    /**
     * 类别修改操作
    */
    public function detailPost(){
        $date        = $this->request->param();
        $g           = new GoodscatModel();
        $where       = array();
        $where['id'] = $date['id'];
        $rest        = $g->detail($where,$date);
        if($rest != false){
            $this->success("操作成功！",url("goodscat/index"));
        }else{
            $this->error('操作失败');
        }
    }
    /**
     * 类别删除操作
    */
    public function del(){
        $date        = $this->request->param();
        $g           = new GoodscatModel();
        $rest        = $g->del($date);
        if($rest != false){
            $this->success("删除成功！",url("goodscat/index"));
        }else{
            $this->error('删除失败',url("goodscat/index"));
        }
    }
    /*禁用启用功能*/
    public function upStatus(){
        $date        = $this->request->param();
        $g           = new GoodscatModel();
        $where       = array();
        $where['id'] = $date['id'];
        $rest        = $g->detail($where,$date);
        if($rest != false){
            $this->success("操作成功！",url("goodscat/index"));
        }else{
            $this->error('操作失败',url("goodscat/index"));
        }
    }
}